<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
         body {
            background: pink;
        }
    </style>
</head>
<body>
   <!--  封装一个十六进制的随机颜色 函数  #fff111 -->
   <button id="btn">点击换色</button>
   <script>

       // 给按钮添加点击事件
       btn.onclick = function () {
           var str='#'
           var arr=["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"];
           for(var i=0;i<6;i++){
               var num=parseInt(Math.random()*16);
               str+=arr[num];
           }

           return document.body.style.background =str
       }
   </script>




</body>
</html>